package com.tianlan.blog.dao;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import com.tianlan.blog.entity.SysDict;

public interface SysDictDao extends JpaRepository<SysDict, Long>{
	
	@Transactional
	@Modifying
	@Query(value = "UPDATE sys_dict SET del_flag = '1' WHERE id = ?1 OR parent_id = ?1 "
	,nativeQuery = true)
	int removeDict(Integer dictId);

	@Query(value = "SELECT id,parent_id,dict_name,dict_code,dict_order,dict_status,description,create_time,creator,update_time,operator,del_flag "
			+ " FROM sys_dict WHERE del_flag = '0' AND FIND_IN_SET(id, queryDictList(:parentId))"
	,nativeQuery = true)
	List<SysDict> queryDictList(@Param("parentId") Integer parentId);
	
	long countByIdAndDelFlag(Integer id,String delFlag);
}
